from fastapi import APIRouter, Depends
from utils.mysql import get_db
from utils.response import success, error
from app.model.user_model import UserModel

userApi = APIRouter(tags=['用户管理'], prefix="/dept")

@userApi.get('/page', summary="用户查询")
def page( db=Depends(get_db)):
    data = UserModel(db).get_page({}, 1, 10)
    return success("OK", data)

@userApi.get('/get', summary="用户详情")
def get(uid: int, db=Depends(get_db)):
    user = UserModel(db).get_by_id(1)
    return success("OK", user)

@userApi.post('/add', summary="添加用户")
def add(db=Depends(get_db)):
    uid = UserModel(db).add({"username":"aasdfasf"})
    return success("OK")

@userApi.post('/edit', summary="编辑用户")
def edit(db=Depends(get_db)):
    r = UserModel(db).edit({"id":2, "username":"123123", "real_name":"张三"})
    print(r)
    return success("OK")

@userApi.post('/del', summary="删除用户")
def delete(db=Depends(get_db)):
    r = UserModel(db).delete(2)
    print(r)
    return success("OK")
